package com.controller.system;

import com.common.core.controller.BaseController;
import com.common.utils.AjaxResult;
import com.common.utils.PageUtils;
import com.system.entity.SysUserEntity;
import com.system.service.SysUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 用户信息表
 *
 * @author yangzhan
 * @email *****@mail.com
 * @date 2022-04-06 21:52:31
 */
@Controller
@RequestMapping("/sysUser")
public class SysUserController extends BaseController {

    @Autowired
    private SysUserService sysUserService;


    /**
     * 跳转到页面
     */
    @GetMapping("/list")
    @RequiresPermissions("system:user:view")
    public String sysUser() {
        return "system/sysuser/list" ;
    }

    /**
     * 用户信息表 添加
     *
     * @param sysUserEntity
     */
    @PostMapping("/add")
    @ResponseBody
    @RequiresPermissions("system:user:view")
    public AjaxResult add(@RequestBody SysUserEntity sysUserEntity) {

        return sysUserService.sysUserAdd(sysUserEntity);
    }

    /**
     * 用户信息表
     *
     * @param ids
     */
    @DeleteMapping("/delete")
    @ResponseBody
    @RequiresPermissions("system:user:delete")
    public AjaxResult delete(@RequestBody List<Integer> ids) {
        return sysUserService.sysUserDel(ids);
    }

    /**
     * @param sysUserEntity 更新数据
     */
    @PutMapping("/update")
    @ResponseBody
    @RequiresPermissions("system:user:update")
    public AjaxResult update(@RequestBody SysUserEntity sysUserEntity) {
        return sysUserService.sysUserUpById(sysUserEntity);
    }

    /**
     * @param sysUserEntity 数据查询
     */
    @PostMapping("/listByPage")
    @ResponseBody
    @RequiresPermissions("system:user:list")
    public AjaxResult findListByPage(@RequestBody SysUserEntity sysUserEntity) {
        sysUserEntity.setPage(PageUtils.pageUtils(sysUserEntity.getPage(), sysUserEntity.getLimit()));
        return sysUserService.sysUserSelectListByPage(sysUserEntity);
    }

}
